﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Diagnostics;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.ComponentModel;
using SanctusSoftware.Releases;
using System.Reflection;
using System.IO;

namespace SanctusSoftware.Music.ChordSheetEditor.Wpf
{
  /// <summary>
  /// Interaction logic for AboutWindow.xaml
  /// </summary>
  public partial class AboutWindow : Window, INotifyPropertyChanged
  {


    #region Events

    public event PropertyChangedEventHandler PropertyChanged;

    private void OnPropertyChanged(string propertyName)
    {
      if (PropertyChanged != null)
      {
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
      }
    }

    #endregion

    #region Properties

    private string _License = string.Empty;

    public string License
    {
      get { return _License; }
      private set
      {
        _License = value;
        OnPropertyChanged("License");
      }
    }

    private ReleaseInformation _ReleaseInformation = null;

    public ReleaseInformation ReleaseInformation
    {
      get { return _ReleaseInformation; }
      private set
      {
        _ReleaseInformation = value;
        OnPropertyChanged("ReleaseInformation");
      }
    }

    private string _AddInPath = string.Empty;
    public string AddInPath
    {
      get { return _AddInPath; }
      private set
      {
        _AddInPath = value;
        OnPropertyChanged("AddInPath");
      }
    }
    

    #endregion

    #region Constructor

    public AboutWindow()
    {
      InitializeComponent();
      this.DataContext = this;
      License = SanctusSoftware.Releases.LicenseResources.GPLv2;
      ReleaseInformation = new ReleaseInformation(Assembly.GetCallingAssembly());
      Uri assemblyUri = new Uri(Assembly.GetExecutingAssembly().CodeBase);
      string assemblyPath = assemblyUri.LocalPath;
      AddInPath = new FileInfo(assemblyPath).DirectoryName;
    }

    #endregion

    #region Event Handlers

    private void _OKButton_Click(object sender, RoutedEventArgs e)
    {
      this.Close();
    }

    private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
    {
      try
      {
        Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
      }
      catch (Exception ex)
      {

      }
      finally
      {
        e.Handled = true;
      }
    } 

    #endregion

  }
}
